package com.adapter;

import java.sql.NClob;
import java.util.ArrayList;

import com.dblibrary.DaoClass;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DoListAdapter extends BaseAdapter {
	Context mContext;
	int count;
	int mDayModeFlag;
	DaoClass dao;
	private int mHurryModeFlag;
	private ArrayList<Bundle> contentList;

	public DoListAdapter(Context applicationContext, int DayModeFlag,
			int HurryModeFlag) {
		super();
		mContext = applicationContext;
		mDayModeFlag = DayModeFlag;
		mHurryModeFlag = HurryModeFlag;
		dao = DaoClass.getInstance(mContext, mDayModeFlag);
		initContentList();
	}
	public void initContentList() {
		if(contentList!=null){
			contentList.clear();
		}
		contentList = dao.selectAll(mHurryModeFlag);
		count =contentList.size();
	}

	@Override
	public int getCount() {
		if (count < 1) {
			count = 0;
		}
		return count;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		TextView tv;
		if (convertView == null) {
			tv = new TextView(mContext);
		} else {
			tv = (TextView) convertView;
		}
		Bundle tmp = new Bundle();
		tmp=contentList.get(position);
		tv.setText(tmp.getString("content"));
		tv.setTextColor(Color.BLACK);
		tv.setTextSize(18.0f);
		tv.setPadding(12, 12, 2, 2);
	    //Typeface face = Typeface.createFromAsset(mContext.getAssets(), "fonts/MILKYWAY.TTF");       
        tv.setTypeface(Typeface.MONOSPACE);
		tv.setTag(tmp.getInt("_id"));
		
		return tv;
	}
}
